<?php

namespace app\admin\model\outhouse;

use app\admin\model\information\Shelves;
use app\admin\model\information\Warehouse;
use think\Db;
use think\Model;
use traits\model\SoftDelete;

class Rdoutrecord extends Model
{

    use SoftDelete;



    // 表名
    protected $name = 'rdoutrecord';

    // 自动写入时间戳字段
    // protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = 'deletetime';


    public function wareHouse(){
        return $this->hasOne('\app\admin\model\information\Warehouse','id','warehouse_id')->field('id,name');
    }
    public function changeWareHouse(){
        return $this->hasOne('\app\admin\model\information\Warehouse','id','warehouse_change_id')->field('id,name');
    }

    public function shelves(){
        return $this->hasOne('\app\common\model\Shelves','id','shelves_id')->field('id,name');
    }

    public function changeShelves(){
        return $this->hasOne('\app\common\model\Shelves','id','shelves_change_id')->field('id,name');
    }


    /* 在其他入库那，共用了，这里就不再重复
     * public function insertMiddlData($cWhCode,$dDate,$cCode,$list,$type = 'in')
    {
        if ($type == 'in') {
            $table  = 'RdRecord08';
            $tables = 'rdrecords08';
        } elseif ($type == 'out') {
            $table  = 'RdRecord09';
            $tables = 'rdrecords09';
        }
        //插入中间库
        $id = time();
        Db::connect('database.inc')->table($table)->insertGetId([
            'bRdFlag'=>1,
            'cVouchType' =>'08' ,
            'cSource' => '库存',
            'cWhCode' => $cWhCode,
            'dDate'=>$dDate,
            'cCode'=>$cCode,
            'bIsSTQc'=>1,
            'bTransFlag'=>1,
            'ID'=>$id,
        ]);
        $i = 0;
        foreach ($list as $k=>$v){
            $i++;
            Db::connect('database.inc')->table($tables)->insert([
                'cInvCode'=>$v['cInvCode'],
                'ID' => $id,
                'AutoID'=>time()+$i,
                'iQuantity' => $v['iQuantity'],
                'iFlag' => 0,
            ]);
        }
    } */
}
